<!-- 代理相关 -->
<template>
	<view class="container">
		<view class="cate">
			<scroll-view class="scroll__view" scroll-x="true">
				<view class="list">
					<view @tap="clickCate(index,item.id)" class="item" v-for="(item,index) in category" :key="index">
						<text :class="active === index?'active':''">{{item.title}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="itemBox">
			<view class="first" @tap="goDetail(first.id)">
				<image :src="first.image_top" mode=""></image>
				<text>{{first.title}}</text>
			</view>
			<view class="item" v-if="index !== 0" v-for="(item,index) in list" :key="index" @tap="goDetail(item.id)">
				<image :src="item.image_input" mode=""></image>
				<view>
					<text>{{item.title}}</text>
					<text>{{item.create_time}}</text>
				</view>
			</view>
		</view>
		<uni-load-more class="loadMore" iconType="circle" :status="loadStatus" :contentText="contentText"></uni-load-more>
	</view>
</template>

<script>
	import {
		agentCategory,
		agentCenter
	} from "@/api/public.js"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				active: 0,
				category: [],
				pageData: {
					page: 1,
					limit: 10,
					id: "",
				},
				first: {},
				list: [],
				loadStatus: "loading",
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多了"
				},
				nodata:false,
			}
		},
		onLoad() {
			agentCategory().then(res => {
				this.category = res.data
				this.clickCate(0, this.category[0].id)
			})
		},
		onReachBottom() {
			if (this.loadStatus == "more")
				(this.loadStatus = "loading"), this.getList();
		},
		methods: {
			getList() {
				agentCenter(this.pageData).then(res => {
					this.loadStatus = "more";
					this.list.push.apply(this.list, res.data[0].list);
					this.first = this.list[0]
					if (res.data[0].list.length < this.pageData.limit) this.loadStatus = "noMore"; //判断所有数据是否加载完成；
					this.pageData.page = this.pageData.page + 1;
					if (this.list.length == 0) {
						this.nodata = true
						this.contentText.contentnomore = '暂无数据'
					} else {
						this.nodata = false
					}
				})
			},
			clickCate(idx, id) {
				this.active = idx
				this.loadStatus = "loading"
				this.pageData = {
					page:1,
					limit:10,
					id:id
				}
				this.first = {}
				this.list = []
				this.getList()
			},
			goDetail(id) {
				uni.navigateTo({
					url: "/pages/center/help/agencyDetail?id=" + id
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.container {
		.cate {
			position: sticky;
			top: 0;
			background-color: #fff;
			z-index: 9;
			padding: 0 30rpx;
			line-height: 100rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: 1rpx solid #f5f5f5;

			.scroll__view {
				width: 100%;
			}

			.list {
				display: flex;

				.item {
					padding: 0 30rpx;
					white-space: nowrap;
					font-size: 24rpx;

					.active {
						color: $theme-color;
						position: relative;
					}

					.active:after {
						content: '';
						position: absolute;
						height: 6rpx;
						width: 20rpx;
						border-radius: 3rpx;
						background-color: $theme-color;
						bottom: -20rpx;
						left: 50%;
						margin-left: -10rpx;
					}
				}

				.item:nth-of-type(1) {
					padding-left: 0;
				}
			}
		}

		.itemBox {
			padding: 20rpx 30rpx;

			.first {
				image {
					width: 100%;
					height: 260rpx;
					background-color: $theme-color;
				}

				text {
					font-size: 28rpx;
					font-weight: 500;
					color: rgba(51, 51, 51, 1);
					height: 60rpx;
					line-height: 60rpx;
					overflow: hidden;
					display: block;
					white-space: nowrap;
					text-overflow: ellipsis;
					margin-bottom: 40rpx;
				}
			}

			.item {
				margin-top: 30rpx;
				display: flex;
				justify-content: space-between;

				image {
					width: 230rpx;
					height: 160rpx;
					background-color: $theme-color;
				}

				view {
					width: 430rpx;
					height: 160rpx;
					padding-bottom: 30rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					border-bottom: 1rpx solid #f5f5f5;
					text-align: justify;

					text:nth-of-type(1) {
						font-size: 28rpx;
						font-weight: 500;
						color: rgba(51, 51, 51, 1);
						height: 80rpx;
						line-height: 40rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						line-clamp: 2;
						-webkit-box-orient: vertical;
					}

					text:nth-of-type(2) {
						height: 20rpx;
						line-height: 20rpx;
						font-size: 20rpx;
						color: #999;
					}
				}
			}
		}
	}
</style>
